﻿using AntdUI;
using WenAntdUI.Helps;

namespace WenAntdUI.Dome
{
    public partial class Form2 : Window
    {
        private readonly AntdUI.PageHeader header;
        private IFreeSql db;
        public Form2()
        {
            this.db = App.GetService<IFreeSql>();
            InitializeComponent();

            this.propertyGrid1.SelectedObject = this.inputQuery1;

            this.header = new AntdUI.PageHeader()
            {
                Height = 35,
                Dock = DockStyle.Top,
                ShowButton = true,
                ShowIcon = true,
                DividerShow = true,
                DividerMargin = 3,
            };
            this.Controls.Add(header);

            this.adminTable1.SetColumns<Aic>();

            //this.adminTable1.QueryData = async s =>
            //{
            //    var aics = new List<Aic>();
            //    for (int i = 0; i < 7; i++)
            //    {
            //        aics.Add(new Aic() { Index = i, Name = i.ToString("000") });
            //    }
            //    //s.PageNumber = 2;
            //    s.TotalCount = 300;

            //    return aics;
            //};

            //this.adminTable1.DataSource = aics;

            //this.adminTable1.SetColumn<Aic>(t => t.Name, a => a.Align = ColumnAlign.Center)
            //    .SetColumn(t => t.Index, "179")
            //    .SetColumn(t => t.IsTest, 60, a => a.Align = ColumnAlign.Center)
            //    .SetColumn(t => t.Index, 200, a => a.Align = ColumnAlign.Center);                  
        }

        public class Aic : EntityBase
        {
            [DisplayName("名称")]
            [Col]
            public string Name { get; set; } = "";

            [DisplayName("序号")]
            [Col]
            public int Index { get; set; }

            //测试不给 DisplayName 编辑 自动生成无
            public int Test { get; set; }

            [DisplayName("是否选中")]
            [Col]
            public bool IsTest { get; set; }

            [DisplayName("测试枚举")]
            [Col]
            public TestType TestType { get; set; }
        }

        public enum TestType
        {
            None,
            Test,
            Ok,
            Pass,
            File,
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            //var aics = new List<Aic>();
            //for (int i = 0; i < 5; i++)
            //{
            //    aics.Add(new Aic() { Index = i, Name = i.ToString("000") });
            //}
            //this.adminTable1.DataSource = aics;

            Msgbox.ShowAsk("测试");
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            var fm = App.GetFormService(typeof(Form1));
            fm.ShowDialog();
        }

        private void InputQuery1_QueryClick(object sender, string e)
        {

        }
    }
}
